import { ConfigEnv, UserConfigExport } from "vite";
import { ArcoResolver } from "unplugin-vue-components/resolvers";
import { viteMockServe } from "vite-plugin-mock";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";

// https://vitejs.dev/config/
export default ({ command }: ConfigEnv): UserConfigExport => {
  return {
    plugins: [
      vue(),
      vueJsx(),
      viteMockServe({
        mockPath: "./mock",
        localEnabled: command == "serve",
        prodEnabled: false,
        logger: true,
        supportTs: true,
      }),
      AutoImport({
        imports: ["vue", "vue-router", "pinia"],
        resolvers: [ArcoResolver()],
        dirs: ["./src/hooks", "./src/components/**/*.tsx"],
        dts: "./auto-import.d.ts",
      }),
      Components({
        resolvers: [
          ArcoResolver({
            importStyle: false,
          }),
        ],
        dirs: "src",
        dts: true,
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
    },
    css: {
      postcss: {
        plugins: [tailwindcss, autoprefixer],
      },
    },
  };
};
